package com.heu.blood.charge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heu.blood.charge.entity.ChargeItemEntity;
import org.apache.logging.log4j.util.Strings;
import org.checkerframework.checker.units.qual.C;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.Query;

import com.heu.blood.charge.dao.ChargeApplicationDao;
import com.heu.blood.charge.entity.ChargeApplicationEntity;
import com.heu.blood.charge.service.ChargeApplicationService;


@Service
public class ChargeApplicationServiceImpl extends ServiceImpl<ChargeApplicationDao, ChargeApplicationEntity> implements ChargeApplicationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        ChargeApplicationEntity entity = new ChargeApplicationEntity();
        if(Strings.isNotBlank((String) params.get("applicationId")))
            entity.setApplicationId((String) params.get("applicationId"));
        if(Strings.isNotBlank((String) params.get("patientId")))
            entity.setPatientId((String) params.get("patientId"));
        if(Strings.isNotBlank((String) params.get("chargeId")))
            entity.setChargeId((String) params.get("chargeId"));
        if(Strings.isNotBlank((String) params.get("isReturn")))
            entity.setIsReturn(Integer.valueOf((String) params.get("isReturn")));


        LambdaQueryWrapper<ChargeApplicationEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Strings.isNotBlank(entity.getApplicationId()),ChargeApplicationEntity::getApplicationId,entity.getApplicationId())
                .eq(Strings.isNotBlank(entity.getChargeId()),ChargeApplicationEntity::getChargeId,entity.getChargeId())
                .eq(Strings.isNotBlank(entity.getPatientId()),ChargeApplicationEntity::getPatientId,entity.getPatientId())
                .eq(entity.getIsReturn() != null,ChargeApplicationEntity::getIsReturn,entity.getIsReturn())
                .eq(ChargeApplicationEntity::getIfShow,1);



        IPage<ChargeApplicationEntity> page = this.page(
                new Query<ChargeApplicationEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}